<template>
  <uni-nav-bar title="邀请" left-icon="left" @clickLeft="navBack" :fixed="true" statusBar></uni-nav-bar>
  <image :src="shareImg" style="width: 100%; height: 94vh" mode="aspectFill" :show-menu-by-longpress="true"></image>
  <webWechat :path="path"></webWechat>
</template>

<script setup lang="ts">
  import { navBack } from '@/utils/navigator';
  import { ref } from 'vue';
  import { toPublish } from '@mqtt';
  import { inviteDriver } from '@/gql/fleet';
  import { showLoading } from '@/utils/prompt';
  import webWechat from '@c/pobulic/webWechat.vue';
  import { useUserStore } from '@/stores/user';
  import { getDriverID } from '@/stores/driverID';
  const userInfo = useUserStore();
  const driver_id = getDriverID();
  /**
   * 车队邀请页面
   * @param {String} shareImg 邀请图
   * @param {String} path 邀请链接
   */
  const shareImg = ref('');
  const path = ref('');
  init();
  function init() {
    showLoading('加载中');
    const fleet_id = Number(userInfo.getFleetAll.id);
    const payload = {
      query: inviteDriver,
      variables: { fleet_id, driver_id },
    };
    toPublish('ql/driver/inviteDriver', payload, (obj : any) => {
      const { inviteDriver } = obj.data;
      const key = Date.now().toString().substr(0, 10);
      path.value = `https://wx.anlan.tech/#/?type=fleetyq&fleet_id=${fleet_id}&from_driver_id=${driver_id}&key=${key}`;
      shareImg.value = inviteDriver.image;
    });
  }
</script>

<style scoped lang="less">
</style>